/**
 * 书刊仓库管理初始化
 */
var Storehouse = {
    id: "StorehouseTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Storehouse.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '编号', field: 'id', visible: true, align: 'center', valign: 'middle'},
            {title: '书刊名', field: 'goodsName', visible: true, align: 'center', valign: 'middle'},
            {title: '总数', field: 'goodsSum', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
Storehouse.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        Storehouse.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加书刊仓库
 */
Storehouse.openAddStorehouse = function () {
    var index = layer.open({
        type: 2,
        title: '添加书刊仓库',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/storehouse/storehouse_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看书刊仓库详情
 */
Storehouse.openStorehouseDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '书刊仓库详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/storehouse/storehouse_update/' + Storehouse.seItem.id
        });
        this.layerIndex = index;
    }
};


Storehouse.openStorehouseDetail1 = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '书刊仓库详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/storehouse/storehouse_chu/' + Storehouse.seItem.id
        });
        this.layerIndex = index;
    }
};

Storehouse.openStorehouseDetail2 = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '书刊仓库详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/storehouse/storehouse_join/' + Storehouse.seItem.id
        });
        this.layerIndex = index;
    }
};
/**
 * 删除书刊仓库
 */
Storehouse.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/storehouse/delete", function (data) {
            Feng.success("删除成功!");
            Storehouse.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("storehouseId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询书刊仓库列表
 */
Storehouse.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    Storehouse.table.refresh({query: queryData});
};

/**
 * 书刊出库
 */
//Storehouse.out=function(){
//	document.getElementById('goodsSum').value = document.getElementById('yu').value - document.getElementById('chu').value;
//	var value ="你确定要出库" +document.getElementById('chu').value + "个商品";//重点在bai此
//	alert(value);
//}

/**
 * 书刊入库
 */

//Storehouse.join = function(){
//	var n=document.getElementById('join').value;
//    var v=${item.goodsSum};
//    v += parseInt(n, 10);
//    document.getElementById('goodsSum').value =v;
//    var value ="你确定要入库" +document.getElementById('join').value + "个商品";
//    alert(value);
//}


$(function () {
    var defaultColunms = Storehouse.initColumn();
    var table = new BSTable(Storehouse.id, "/storehouse/list", defaultColunms);
    table.setPaginationType("client");
    Storehouse.table = table.init();
});
